<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>购物车</title>
<script type="text/javascript" src="../js/jquery-3.1.0.min.js"></script>
<link rel="stylesheet" href="css/style.css" type="text/css">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript">
	$(document).ready(function() {
		var TotalPage = ${TotalPage};
		var CurrentPage = ${CurrentPage};
		$("#next").click(function() {
			if (CurrentPage ==TotalPage) {
				alert("当前页已经是最后一页啦");
			} else {
				CurrentPage++;
					getList();
			}
		});
		$("#previous").click(function() {
			if (CurrentPage == 1) {
				alert("当前页已经是第一页啦");
			} else {
				CurrentPage--;
				getList();
			}
		});
		
		$("#first").click(function() {
			CurrentPage=1;
			getList();
		});
		$("#last").click(function() {
			CurrentPage = TotalPage;
			getList();
		});
		
		$("#search").click(function(){
			CurrentPage=1;
			getList();
		});
		function getList(){
			var keyName = $("#keyName ").val();
			location.href="ShoppingcartListServlet?CurrentPage="+CurrentPage+"&keyName="+keyName;
		}
		
	});
</script>
</head>
<body>
<div align="right">
		<a href="GetGoodsListServlet" style="color: orange; text-decoration: none;">商城主页</a> 
		<a href="ShoppingcartListServlet"style="color: orange; text-decoration: none;">我的购物车</a> 
		<a href="GetBuyerOrderListServlet" style="color: orange; text-decoration: none;">我的订单</a> 
		<a href="userinformation.jsp" style="color: orange; text-decoration: none;">个人信息</a>
	</div>
	<hr color="orange" size="5pt">

<div>
	商品名称：<input type="text" id="keyName" value="${param.keyName}">
	<input type="button" id="search" value="查询">
		
			<table border="1" width="100%" bgcolor="orange">
				<tr>
					<td><input type="button" value="清空购物车"  onclick="clearShoppingcart()"></td>
					<td><input type="button" value="统一下单"  onclick="buyAllShoppingcart()"></td>
				</tr>
				<tr>
					<th>商品类型</th><th>商品名称</th><th>价格</th><th>存货</th><th>店铺名称</th><th>店铺老板</th><th>联系方式</th><th>数量</th><th>总价</th><th>操作</th>
				</tr>
				<c:forEach items="${shoppingcartList}" var="shoppingcart">
					<tr>			
						<td>${shoppingcart.good.goodsType.goodstype_name}</td><td>${shoppingcart.good.gName}</td><td>${shoppingcart.good.gPrice}</td><td>${shoppingcart.good.gAccount}</td><td>${shoppingcart.user.userShopName}</td><td>${shoppingcart.user.userName}</td><td>${shoppingcart.user.userPhone}</td><td>${shoppingcart.goods_num}</td>
						<td>${shoppingcart.goods_num * shoppingcart.good.gPrice}</td>
						<td>
							<input type="button" value="删除" class="del" onclick="del(${shoppingcart.shoppingcart_id},${CurrentPage})">
							<input type="button" value="下单" class="buy" onclick="buy(${shoppingcart.shoppingcart_id},${CurrentPage})">
						</td>
					</tr>
				</c:forEach>
			</table>
		 	<input type="button" value=" 第一页" id="first"> 
		 	<input type="button" value=" 上一页" id="previous"> 
		 	<input type="button" value="下一页" id="next">
		 	<input type="button" value="最后页"id="last">
		 	${CurrentPage}/${TotalPage}
</div>

<script type="text/javascript">
function del(shoppingcart_id,CurrentPage){
	if(confirm("是否确定删除?")){
		location.href = "DelShoppingCartServlet?CurrentPage=" +CurrentPage +"&shoppingcart_id="+shoppingcart_id+"&keyName="+keyName;
	}
}
function buy(shoppingcart_id,CurrentPage){
	location.href ="BuyShoppingCartServlet?shoppingcart_id="+shoppingcart_id + "&CurrentPage="+CurrentPage+"&keyName="+keyName;		
}

function clearShoppingcart(){
	if(confirm("是否确定清空购物车?")){
		location.href = "ClearShoppingCartServlet";	
	}
}
function buyAllShoppingcart(){
	if(confirm("是否确定统一下单?")){
		location.href = "BuyAllShoppingcartServlet";	
	}
	
}
</script>
</body>
</html>